package spring.tutorial;

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import spring.tutorial.domain.Moim;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "file:web/WEB-INF/applicationContext.xml")
public class InsertDataUtil {

	@Autowired
	private SessionFactory factory;

	public void setFactory(SessionFactory factory) {
		this.factory = factory;
	}

	@Test
	public void insertData() {

		Moim firstMoim = new Moim(new Date(), "STUDY", "To Stuty~Very Hard~");

		Moim secondMoim = new Moim(new Date(), "ENJOY", "Sing a Song~");

		Session session = factory.openSession();
		session.beginTransaction();

		session.save(firstMoim);
		session.save(secondMoim);

		session.getTransaction().commit();
		session.close();
	}
}
